<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
    <script src="js/browser.min.js"></script>
    <script></script>
</head>
<body>
    <div id='example'></div>

    <script type="text/babel">
        var TestComponent = React.createClass({
            getInitialState:function(){
                return {
                    count:1
                }
            },
            componentWillMount:function(){
                console.log('组件准备挂载');
                console.log(this.refs.myHeader);
            },
            componentDidMount:function(){
                console.log('组件已经挂载成功');
                console.log(this.refs.myHeader);
            },
            //什么时候会触发和update相关的钩子函数?
            //①当组件内部的状态发生变化
            //②当调用组件时 通过属性传递来的值发生变化
            componentWillUpdate:function(nextProps,nextState){
                console.log('update处理函数被调用了');
                console.log(nextProps,nextState);
            },
            componentDidUpdate:function(prevProps,prevState){
                console.log('数据更新完成！');
                console.log(prevProps,prevState);
            },
            handleClick:function(){
                //修改状态中的值
                this.setState({count:2});
            },
            render:function(){
                return <div>
                <h1 ref="myHeader">Hello React</h1>
                <button onClick={this.handleClick}>
                    clickMe
                </button>
                </div>
            }
        });

        ReactDOM.render(
            <TestComponent></TestComponent>,
            document.getElementById('example')
        );
    </script>
</body>
</html>